<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>上传歌星</title>
</head>
<style>
  .container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 500px;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
  form input[type="text"],
  form select,
  form input[type="file"] {
    width: 100%;
    padding: 5px;
    margin-bottom: 10px;
    margin-top: 15px;
  }
  form button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
  }
</style>
<body>
  <div class="container">
    <form method="post" action="your-endpoint" enctype="multipart/form-data" id="myForm">
      姓名: <input type="text" name="name"><br>
      性别: <select name="gender" id="gender">
        <option value="1">男</option>
        <option value="2">女</option>
      </select>  <br>
      国籍: <input type="text" name="country"><br>
      音乐类型:
        <select name="musicStyle" id="musicStyle">
          <option value="1">流行</option>
          <option value="2">摇滚</option>
          <option value="3">民谣</option>
          <option value="4">蓝调</option>
          <option value="5">爵士</option>
          <option value="6">funk</option>
          <option value="7">重金属</option>
          <option value="8">古典</option>
          <option value="9">电子音乐</option>
          <option value="10">fusion</option>
        </select><br>
      头像:<input type="file" name="file" /><br>
      <!-- 其他表单字段 -->
      <button type="submit">提交</button>
  </form>
  </div>
  <script>
    const form = document.querySelector('#myForm')
    form.addEventListener('submit',(e)=>{
      e.preventDefault();
      const formData = new FormData(form);
        // 获取上传的文件信息
        const file = formData.get('file');
        const name = formData.get('name');
        const country = formData.get('country');
        const gender = formData.get('gender')
        const musicStyle = formData.get('musicStyle')

        const video = {
          "name":name,
          "file":file,
          "image":"520",
          "style":musicStyle,
          "country":country,
          "gender":gender
        }
        axios({
          url:'http://localhost:8080/stars',
          method:"post",
          data:video,
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }).then(result => {
          console.log(result);
          form.reset()
        })
    })
  </script>
  <script src="axios.min.js"></script>
</body>
</html>